

cap log close 
clear all
set more off 
set niceness 10

gl MAIN = "/Users/Wei/Dropbox"
*gl MAIN = "C:\Users\huang\Dropbox"

gl path1 = "$MAIN/CFPS/cfps_official"
gl path2 = "$MAIN/Fertility/Workingdata"
gl path3 = "$MAIN/Fertility/Results"
gl path4 = "$MAIN/Fertility/Results"

log using "$path4/cfps_results.log", replace 
/*
cd "$path1/fulllaunch10"
unicode encoding set gb18030
unicode translate cfps2010adult_report.dta, invalid
unicode translate cfps2010family_report.dta, invalid
*/
gl CONTROL_1 = "women#prov##c.year_birth women#year_birth#year" 
gl CONTROL_2 = "women#prov##c.year_birth women#year_birth#year prov#year" 

gl FINE_ALL = "fine_6_15 fine_16_20"
gl FINE_VAR_1 = "fine_6_20"


use "$path2/CFPS_OCP", clear 

keep if !mi(happy) | !mi(sat_marr)

* Table 1 Panel C
su age senior happiness sat_marr sat_duty_other agree_women_marr agree_women_chid if women & !mi(happy)
su age senior happiness sat_marr sat_duty_other agree_women_marr agree_women_chid if men & !mi(happy)


cap erase "$path3/tab_6.xls"
cap erase "$path3/tab_6.txt"

foreach CONTROL in "$CONTROL_1"{
foreach y_var in  "happiness" "sat_marr"  "sat_duty_other" "agree_women_marr"  "agree_women_chid"{ 

reghdfe `y_var' women#c.($FINE_VAR_1) , a(`CONTROL') cluster(prov)
su `y_var' if women 
local mean_women = `r(mean)'
su `y_var' if men 
local mean_men = `r(mean)'
test  (1.women#c.$FINE_VAR_1 = 0.women#c.$FINE_VAR_1) 
local F_gender = `r(F)'
local p_gender = `r(p)'
outreg2 using "$path3/tab_6.xls", append dec(3) adds(mean-men, `mean_men',  mean-women,`mean_women', F-stat, `F_gender', p-value, `p_gender')


}


}


use "$path2/CFPS_OCP", clear 
keep if women == 1 
keep if year < 2014
keep if age < 60 & age > 25

replace age = year - year_birth
su finc* pce 

replace lnpce = . if lnpce < 7 | lnpce > 13
replace lnfinc_per = . if lnfinc_per < 5 | lnfinc_per > 13
replace lnfinc_net_per = . if lnfinc_net_per < 5 | lnfinc_net_per > 13
gen sav_rate = (finc_net - pce)/finc_net
drop  if sav_rate < -5

gen lnpce_per = lnpce - (lnfinc_net - lnfinc_net_per)
gl CONTROL_1 = "women#prov##c.year_birth women#year_birth#year" 


reghdfe senior women#c.($FINE_VAR_1) , a($CONTROL_1) cluster(prov)
su senior 
outreg2 using "$path3/tab_c16.xls",replace dec(3) adds(Mean, `r(mean)')

foreach y_var in  "lnfinc_net_per"{
reghdfe `y_var'  women#c.($FINE_VAR_1), a($CONTROL_1) cluster(prov)
su `y_var'  
outreg2 using "$path3/tab_c16.xls",append dec(3)  adds(Mean, `r(mean)')
reghdfe `y_var'  women#c.($FINE_VAR_1) if !mi(lnpce_per), a($CONTROL_1) cluster(prov)
su `y_var'   if !mi(lnpce_per)
outreg2 using "$path3/tab_c16.xls",append dec(3)  adds(Mean, `r(mean)')
}

reghdfe lnpce_per women#c.($FINE_VAR_1) , a($CONTROL_1) cluster(prov)
su lnpce_per 
outreg2 using "$path3/tab_c16.xls",append dec(3) adds(Mean, `r(mean)')

log close

